package com.wofish.web.controller.goods;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.wofish.common.annotation.Log;
import com.wofish.common.enums.BusinessType;
import com.wofish.goods.domain.Brand;
import com.wofish.goods.service.IBrandService;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.utils.poi.ExcelUtil;

import io.swagger.annotations.*;

/**
 * 品牌 信息操作处理
 * 
 * @author wofish
 * @date 2019-06-06
 */

@Api("品牌管理")
@Controller
@RequestMapping("/goods/brand")
public class BrandController extends BaseController {
    private String prefix = "goods/brand";
	
	@Autowired
	private IBrandService brandService;
	
	@RequiresPermissions("goods:brand:view")
	@GetMapping()
	public String brand() {
	    return prefix + "/brand";
	}
	
	/**
	 * 查询品牌列表
	 */

	@ApiOperation("获取品牌列表")
	@RequiresPermissions("goods:brand:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Brand brand) {
		startPage();
        List<Brand> list = brandService.selectBrandList(brand);
		return getDataTable(list);
	}

	@PostMapping("/brandList")
	@ResponseBody
	public List<Brand> brandList(Brand brand) {
		List<Brand> list = brandService.selectBrandList(brand);
		return list;
	}

	@PostMapping("/brandListByTypeId")
	@ResponseBody
	public AjaxResult brandListByTypeId(@RequestParam Long typeId) {
		List<Brand> list = brandService.selectBrandByTypeId(typeId);
		return AjaxResult.success(list);
	}
	



	/**
	 * 导出品牌列表
	 */
	@RequiresPermissions("goods:brand:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Brand brand) {
		List<Brand> list = brandService.selectBrandList(brand);
        ExcelUtil<Brand> util = new ExcelUtil<Brand>(Brand.class);
        return util.exportExcel(list, "brand");
    }
	
	/**
	 * 新增品牌
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存品牌
	 */
	@ApiOperation("新增保存品牌")
	@ApiImplicitParam(name = "brand", value = "新增品牌信息", dataType = "Brand")
	@RequiresPermissions("goods:brand:add")
	@Log(title = "品牌", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Brand brand) {
		return toAjax(brandService.insertBrand(brand));
	}

	/**
	 * 修改品牌
	 */
	@GetMapping("/edit/{brandId}")
	public String edit(@PathVariable("brandId") Long brandId, ModelMap mmap) {
		Brand brand = brandService.selectBrandById(brandId);
		mmap.put("brand", brand);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存品牌
	 */

	@ApiOperation("更新品牌")
	@ApiImplicitParam(name = "brand", value = "更新品牌信息", dataType = "Brand")
	@RequiresPermissions("goods:brand:edit")
	@Log(title = "品牌", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Brand brand) {
		return toAjax(brandService.updateBrand(brand));
	}
	
	/**
	 * 删除品牌
	 */

	@ApiOperation("删除品牌")
	@ApiImplicitParam(name = "brandId", value = "品牌ID", required = true, dataType = "Long")
	@RequiresPermissions("goods:brand:remove")
	@Log(title = "品牌", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(brandService.deleteBrandByIds(ids));
	}
	
}
